<?xml version="1.0"?>
<!--
  ~ Copyright 2004-2012 ICEsoft Technologies Canada Corp.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the
  ~ License. You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an "AS
  ~ IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  ~ express or implied. See the License for the specific language
  ~ governing permissions and limitations under the License.
  -->

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:ace="http://www.icefaces.org/icefaces/components" 
    xmlns:ice="http://www.icesoft.com/icefaces/component" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    template="/resources/templates/content-template.xhtml">
    
    <ui:param name="title" value="#{msgs[dataTableDynamic.title]}"/>
    <ui:param name="description" value="#{msgs[dataTableDynamic.description]}"/>
    <ui:param name="resourceValue" value="#{dataTableDynamic.exampleResource}"/>
    
    <ui:param name="wikiResources" value="#{compatComponentsResources.wikiResources}"/>
    <ui:param name="tldResources" value="#{compatComponentsResources.tldResources}"/>
    
    <ui:define name="example">
        <h:form>
            <h:commandButton value="Restore Default Cars"
                             actionListener="#{dataTableDynamic.restoreDefault}"/>
            <h:commandButton value="Add #{dataTableDynamic.bulkNumber} Cars"
                             actionListener="#{dataTableDynamic.bulkAdd}"/>
        </h:form>
        
        <br/>
    
        <h:form>
            <h:panelGrid columns="3" columnClasses="col25,col50,col25"
                         width="85%" style="border: 1px solid #CDCDCD;">
                <h:outputLabel for="nameIn" value="Name:"/>
                <h:inputText id="nameIn" value="#{dataTableDynamic.toModify.name}"
                             required="true" size="15" maxlength="50">
                     <f:validateLength minimum="1" maximum="50"/>
                </h:inputText>
                <h:message for="nameIn"/>
                
                <h:outputLabel for="chassisIn" value="Chassis:"/>
                <h:selectOneMenu id="chassisIn" value="#{dataTableDynamic.toModify.chassis}"
                                 required="true">
                     <f:selectItem itemValue="" itemLabel="-- Select --"/>
                     <f:selectItems value="#{dataTableDynamic.chasisOptions}"/>
                </h:selectOneMenu>
                <h:message for="chassisIn"/>
                
                <h:outputLabel for="weightIn" value="Weight:"/>
                <h:panelGroup>
                    <h:inputText id="weightIn" value="#{dataTableDynamic.toModify.weight}"
                                 required="true" size="5" maxlength="5">
                         <f:validateLongRange minimum="500" maximum="20000"/>
                    </h:inputText>
                    lbs.
                </h:panelGroup>
                <h:message for="weightIn"/>
                
                <h:outputLabel for="accelIn" value="Acceleration:"/>
                <h:selectOneRadio id="accelIn" value="#{dataTableDynamic.toModify.acceleration}"
                                  required="true">
                      <f:selectItem itemValue="5" itemLabel="5"/>
                      <f:selectItem itemValue="10" itemLabel="10"/>
                      <f:selectItem itemValue="15" itemLabel="15"/>
                      <f:selectItem itemValue="20" itemLabel="20"/>
                </h:selectOneRadio>
                <h:message for="accelIn"/>
                
                <h:outputLabel for="mpgIn" value="MPG:"/>
                <h:inputText id="mpgIn" value="#{dataTableDynamic.toModify.mpg}"
                             required="true" size="5" maxlength="5">
                     <f:validateDoubleRange minimum="1" maximum="60"/>
                </h:inputText>
                <h:message for="mpgIn"/>
                
                <h:outputLabel for="costIn" value="Cost:"/>
                <h:inputText id="costIn" value="#{dataTableDynamic.toModify.cost}"
                             required="true" size="10" maxlength="10">
                    <f:validateLongRange minimum="500" maximum="75000"/>
                    <f:convertNumber type="currency"
                                     currencySymbol="$"
                                     groupingUsed="true"
                                     minFractionDigits="2"
                                     maxFractionDigits="2"/>                             
                </h:inputText>
                <h:message for="costIn"/>
                
                <f:facet name="footer">
                    <h:commandButton value="Submit Car"
                                     actionListener="#{dataTableDynamic.submitItem}"/>
                </f:facet>
            </h:panelGrid>
        </h:form>
        
        <br/>
        
        <h:form>
            <ice:dataTable value="#{dataTableDynamic.carsData}"
                           var="car"
                           width="100%" cellspacing="1" cellpadding="5"
                           columnClasses="tableIdCol,tableNameCol,tableChassisCol,
                                          tableWeightCol,tableAccelCol,tableMpgCol,tableCostCol,tableIdCol">
                <ice:column>
                    <f:facet name="header">ID</f:facet>
                    #{car.id}
                </ice:column>
                <ice:column>
                    <f:facet name="header">Name</f:facet>
                    #{car.name}
                </ice:column>
                <ice:column>
                    <f:facet name="header">Chassis</f:facet>
                    #{car.chassis}
                </ice:column>
                <ice:column>
                    <f:facet name="header">Weight</f:facet>
                    #{car.weight}lbs.
                </ice:column>
                <ice:column>
                    <f:facet name="header">Accel</f:facet>
                    #{car.acceleration}
                </ice:column>
                <ice:column>
                    <f:facet name="header">MPG</f:facet>
                    #{car.mpg}
                </ice:column>
                <ice:column>
                    <f:facet name="header">Cost</f:facet>
                    <ice:outputText value="#{car.cost}">
                        <f:convertNumber type="currency"
                                         currencySymbol="$"
                                         groupingUsed="true"
                                         minFractionDigits="2"
                                         maxFractionDigits="2"/>
                    </ice:outputText>
                </ice:column>
                <ice:column>
                    <f:facet name="header">Edit</f:facet>
                    <h:commandButton image="resources/css/images/edit-page.png"
                                     alt="Edit" title="Edit"
                                     style="height: 11px; width: 11px;"
                                     action="#{dataTableDynamic.editItem}">
                         <f:setPropertyActionListener target="#{dataTableDynamic.toEdit}"
                                                      value="#{car.id}"/>
                    </h:commandButton>
                </ice:column>
                <ice:column>
                    <f:facet name="header">Del</f:facet>
                    <h:commandButton image="resources/css/images/popup-close.png"
                                     alt="Delete" title="Delete"
                                     style="height: 11px; width: 11px;"
                                     action="#{dataTableDynamic.removeItem}">
                         <f:setPropertyActionListener target="#{dataTableDynamic.toRemove}"
                                                      value="#{car.id}"/>
                    </h:commandButton>
                </ice:column>
            </ice:dataTable>
        </h:form>
    </ui:define>
</ui:composition>
